home *** CD-ROM | disk | FTP | other *** search
/ Winzipper / Winzipper_ISO.iso / programming / oracle7 7.2 / DB / UTIL72 / UTLESTAT.SQL < prev    next >
Encoding:
Text File  |  1995-05-09  |  10.0 KB  |  299 lines

  1. rem 
  2. rem $Header: utlestat.sql 7020100.1 94/09/23 22:14:42 cli Generic<base> $ estat.sql 
  3. rem 
  4. Rem Copyright (c) 1988 by Oracle Corporation
  5. Rem NAME
  6. REM    UTLESTAT.SQL
  7. Rem  FUNCTION
  8. Rem    This script will generate a report (in "report.txt") which will contain
  9. Rem    usefull information for performance monitoring.  In particular
  10. Rem    information from v$sysstat, v$latch, and v$rollstat.
  11. Rem  NOTES
  12. Rem    Don't worry about errors during "drop table"s, they are normal.
  13. Rem  MODIFIED
  14. Rem     drady      09/09/93 -  merge changes from branch 1.1.312.2
  15. Rem     drady      04/26/93 -  Stat name changes for 7.1 
  16. Rem     drady      03/22/93 -  merge changes from branch 1.1.312.1 
  17. Rem     drady      08/24/93 -  bug 173918
  18. Rem     drady      03/04/93 -  fix bug 152986 
  19. Rem     glumpkin   11/23/92 -  Creation 
  20. Rem     glumpkin   11/23/92 -  Renamed from UTLSTATE.SQL 
  21. Rem     glumpkin   10/20/92 -  Renamed from ESTAT.SQL 
  22. Rem     jloaiza    03/26/92 -  add write queue query 
  23. Rem     jloaiza    02/24/92 -  fix latch stats 
  24. Rem     jloaiza    01/17/92 -  improve output 
  25. Rem     jloaiza    01/07/92 -  rework for version 7
  26. Rem   Laursen    01/01/91 - V6 to V7 merge
  27. Rem   Trabosh    09/27/89 - added order by and group by to stats$files
  28. Rem   Loaiza     04/04/89 - fix run dates to do minutes instead of months
  29. Rem   Loaiza     03/31/89 - add kqrst usage column
  30. Rem   Jloaiza    03/16/89 - improve names and formats
  31. Rem   Jloaiza    03/09/89 - make kqrst columns intelligible
  32. Rem   Jloaiza    02/23/89 - changed table names, added dates
  33. Rem   Martin     02/22/89 - Creation
  34. set echo on;
  35. connect internal;
  36.  
  37. Rem ********************************************************************
  38. Rem                Gather Ending Statistics
  39. Rem ********************************************************************
  40.  
  41. insert into stats$end_event select * from v$system_event;
  42. insert into stats$end_latch select * from v$latch;
  43. insert into stats$end_roll select * from v$rollstat;
  44. insert into stats$end_file select * from stats$file_view;
  45. insert into stats$end_stats select * from v$sysstat;
  46. insert into stats$end_dc select * from v$rowcache;
  47. insert into stats$end_lib select * from v$librarycache;
  48. insert into stats$dates 
  49.    select to_char(sysdate, 'dd-mon-yy hh24:mi:ss') from dual;
  50.  
  51.  
  52. Rem ********************************************************************
  53. Rem                Create Summary Tables
  54. Rem ********************************************************************
  55.  
  56. drop table stats$stats;
  57. drop table stats$latches;
  58. drop table stats$roll;
  59. drop table stats$files;
  60. drop table stats$dc;
  61. drop table stats$lib;
  62. drop table stats$event;
  63.  
  64. create table stats$stats as
  65. select  e.value-b.value change , n.name
  66.    from v$statname n ,  stats$begin_stats b , stats$end_stats e
  67.     where n.statistic# = b.statistic# and n.statistic# = e.statistic#;
  68.  
  69. create table stats$latches as
  70. select     e.gets-b.gets gets, 
  71.     e.misses-b.misses misses,
  72.     e.sleeps-b.sleeps sleeps,
  73.     e.immediate_gets-b.immediate_gets immed_gets,
  74.     e.immediate_misses-b.immediate_misses immed_miss,
  75.     n.name
  76.    from v$latchname n ,  stats$begin_latch b , stats$end_latch e
  77.     where n.latch# = b.latch# and n.latch# = e.latch#;
  78.  
  79. create table stats$event as
  80.   select  e.total_waits-b.total_waits event_count,
  81.           e.time_waited-b.time_waited time_waited,
  82.           e.event
  83.     from  stats$begin_event b , stats$end_event e
  84.     where b.event = e.event
  85.   union
  86.   select  e.total_waits event_count,
  87.           e.time_waited time_waited,
  88.           e.event    
  89.     from  stats$end_event e
  90.     where e.event not in (select b.event from stats$begin_event b);
  91.  
  92. create table stats$roll as
  93. select  e.usn undo_segment,
  94.         e.gets-b.gets trans_tbl_gets, 
  95.     e.waits-b.waits trans_tbl_waits, 
  96.     e.writes-b.writes undo_bytes_written,
  97.     e.rssize segment_size_bytes,
  98.         e.xacts-b.xacts xacts,
  99.     e.shrinks-b.shrinks shrinks,
  100.         e.wraps-b.wraps wraps
  101.    from stats$begin_roll b, stats$end_roll e
  102.         where e.usn = b.usn;
  103.  
  104. create table stats$files as
  105. select b.ts table_space,
  106.        b.name file_name,
  107.        e.pyr-b.pyr phys_reads,
  108.        e.pbr-b.pbr phys_blks_rd,
  109.        e.prt-b.prt phys_rd_time,
  110.        e.pyw-b.pyw phys_writes,
  111.        e.pbw-b.pbw phys_blks_wr,
  112.        e.pwt-b.pwt phys_wrt_tim
  113.   from stats$begin_file b, stats$end_file e
  114.        where b.name=e.name;
  115.  
  116. create table stats$dc as
  117. select b.parameter name,
  118.        e.gets-b.gets get_reqs,
  119.        e.getmisses-b.getmisses get_miss,
  120.        e.scans-b.scans scan_reqs,
  121.        e.scanmisses-b.scanmisses scan_miss,
  122.        e.modifications-b.modifications mod_reqs,
  123.        e.count count,
  124.        e.usage cur_usage
  125.   from stats$begin_dc b, stats$end_dc e
  126.        where b.cache#=e.cache# 
  127.         and  nvl(b.subordinate#,-1) = nvl(e.subordinate#,-1);
  128.  
  129. create table stats$lib as
  130. select e.namespace,
  131.        e.gets-b.gets gets,
  132.        e.gethits-b.gethits gethits,
  133.        e.pins-b.pins pins,
  134.        e.pinhits-b.pinhits pinhits,
  135.        e.reloads - b.reloads reloads,
  136.        e.invalidations - b.invalidations invalidations
  137.   from stats$begin_lib b, stats$end_lib e
  138.        where b.namespace = e.namespace;
  139.  
  140.  
  141. Rem *******************************************************************
  142. Rem              Output statistics
  143. Rem *******************************************************************
  144.  
  145. spool report.txt;
  146.  
  147. set charwidth 12
  148. set numwidth 10
  149. Rem Select Library cache statistics.  The pin hit rate shoule be high.
  150. select namespace library,
  151.        gets, 
  152.        round(decode(gethits,0,1,gethits)/decode(gets,0,1,gets),3) 
  153.           gethitratio,
  154.        pins, 
  155.        round(decode(pinhits,0,1,pinhits)/decode(pins,0,1,pins),3) 
  156.           pinhitratio,
  157.        reloads, invalidations
  158.   from stats$lib;
  159.  
  160. set charwidth 27;
  161. set numwidth 12;
  162. Rem The total is the total value of the statistic between the time
  163. Rem bstat was run and the time estat was run.  Note that the estat
  164. Rem script logs on as "internal" so the per_logon statistics will
  165. Rem always be based on at least one logon.
  166. select n1.name "Statistic", 
  167.        n1.change "Total", 
  168.        round(n1.change/trans.change,2) "Per Transaction",
  169.        round(n1.change/logs.change,2)  "Per Logon"
  170.    from stats$stats n1, stats$stats trans, stats$stats logs
  171.    where trans.name='user commits'
  172.     and  logs.name='logons cumulative'
  173.     and  n1.change != 0
  174.    order by n1.name;
  175.  
  176. set charwidth 27;
  177. set numwidth 12;
  178. Rem System wide wait events.
  179. select     n1.event "Event Name", 
  180.            n1.event_count "Count",
  181.     n1.time_waited "Total Time",
  182.     (n1.time_waited/n1.event_count) "Average Time"
  183.    from stats$event n1
  184.    where n1.event_count > 0
  185.    order by n1.time_waited desc;
  186.  
  187. set numwidth 27
  188. Rem Average length of the dirty buffer write queue.  If this is larger than
  189. Rem the value of the db_block_write_batch init.ora parameter, then consider
  190. Rem increasing the value of db_block_write_batch and check for disks that
  191. Rem are doing many more IOs than other disks.
  192. select queue.change/writes.change "Average Write Queue Length"
  193.   from stats$stats queue, stats$stats writes
  194.  where queue.name  = 'summed dirty queue length'
  195.   and  writes.name = 'write requests';
  196.  
  197. set charwidth 48;
  198. set numwidth 12;
  199. Rem I/O should be spread evenly accross drives. A big difference between
  200. Rem phys_reads and phys_blks_rd implies table scans are going on.
  201. select * from 
  202.   stats$files order by table_space, file_name;
  203.  
  204. set charwidth 80
  205. Rem sum over tablespaces
  206. select
  207.   table_space||'                                                 ' 
  208.      table_space,
  209.   sum(phys_reads) phys_reads,  sum(phys_blks_rd) phys_blks_rd,
  210.   sum(phys_rd_time) phys_rd_time,  sum(phys_writes) phys_writes,
  211.   sum(phys_blks_wr) phys_blks_wr,  sum(phys_wrt_tim) phys_wrt_tim
  212.  from stats$files
  213.  group by table_space
  214.  order by table_space;
  215.  
  216. set charwidth 18;
  217. set numwidth 11;
  218. Rem Sleeps should be low.  The hit_ratio should be high.
  219. select name latch_name, gets, misses,
  220.     round(decode(gets-misses,0,1,gets-misses)/decode(gets,0,1,gets),3) 
  221.       hit_ratio,
  222.     sleeps,
  223.     round(sleeps/decode(misses,0,1,misses),3) "SLEEPS/MISS"
  224.    from stats$latches 
  225.     where gets != 0
  226.     order by name;
  227.  
  228. set numwidth 18
  229. Rem Statistics on no_wait gets of latches.  A no_wait get does not wait for the
  230. Rem latch to become free, it immediately times out.
  231. select name latch_name,
  232.     immed_gets nowait_gets,
  233.     immed_miss nowait_misses,
  234.     round(decode(immed_gets-immed_miss,0,1,immed_gets-immed_miss)/
  235.            decode(immed_gets,0,1,immed_gets),
  236.           3)     
  237.       nowait_hit_ratio 
  238.    from stats$latches 
  239.     where immed_gets != 0
  240.     order by name;
  241.  
  242.  
  243. set numwidth 19;
  244. Rem Waits_for_trans_tbl high implies you should add rollback segments.
  245. select * from stats$roll;
  246.  
  247. set charwidth 39
  248. Rem The init.ora parameters currently in effect:
  249. select name, value from v$parameter where isdefault = 'FALSE' order by name;
  250.  
  251. set charwidth 15;
  252. set numwidth 8;
  253. Rem get_miss and scan_miss should be very low compared to the requests.
  254. Rem cur_usage is the number of entries in the cache that are being used.
  255. select * from stats$dc
  256.  where get_reqs != 0 or scan_reqs != 0 or mod_reqs != 0;
  257.  
  258.  
  259. set charwidth 20
  260. Rem The times that bstat and estat were run.
  261. select * from stats$dates;
  262.  
  263. spool off;
  264.  
  265. Rem ********************************************************************
  266. Rem                 Drop Temporary Tables
  267. Rem ********************************************************************
  268.  
  269. drop table stats$dates;
  270.  
  271. drop table stats$begin_stats;
  272. drop table stats$end_stats;
  273. drop table stats$stats;
  274.  
  275. drop table stats$begin_latch;
  276. drop table stats$end_latch;
  277. drop table stats$latches;
  278.  
  279. drop table stats$begin_roll;
  280. drop table stats$end_roll;
  281. drop table stats$roll;
  282.  
  283. drop table stats$begin_file;
  284. drop table stats$end_file;
  285. drop table stats$files;
  286. drop view stats$file_view;
  287.  
  288. drop table stats$begin_dc;
  289. drop table stats$end_dc;
  290. drop table stats$dc;
  291.  
  292. drop table stats$begin_lib;
  293. drop table stats$end_lib;
  294. drop table stats$lib;
  295.  
  296. drop table stats$begin_event;
  297. drop table stats$end_event;
  298. drop table stats$event;
  299.